import collections


class Solution(object):
    def highFive(self, items):
        """
        :type items: List[List[int]]
        :rtype: List[List[int]]
        """
        id_set = set()
        score_dict = collections.defaultdict(list)
        for item in items:
            score_dict[item[0]].append(item[1])
            id_set.add(item[0])
        out = []
        id_list = list(id_set)
        id_list.sort()
        for id in id_list:
            score_dict[id].sort(reverse=True)
            out.append([id, sum(score_dict[id][: 5]) // 5])
        return out


data = Solution()
items = [[1, 91], [1, 92], [2, 93], [2, 97], [1, 60], [2, 77], [1, 65], [1, 87], [1, 100], [2, 100], [2, 76]]
print(data.highFive(items))
items = [[1, 100], [7, 100], [1, 100], [7, 100], [1, 100], [7, 100], [1, 100], [7, 100], [1, 100], [7, 100]]
print(data.highFive(items))
